<html>
<head>
<title>Edit a record of event_question</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link media="all" href="/cms/css/cms.min.css" type="text/css" rel="stylesheet" /> 
<link rel="stylesheet" type="text/css" href="/cms/css/tag/token-input.css" />
<script  type="text/javascript" src="/cms/js/cms.1.1.min.js"></script>
<script type="text/javascript" src="/cms/js/tag/jquery.tokeninput.js"></script>
<script language="JavaScript" src="/cms/js/cleditor/jquery.cleditor.min.js"></script>
<!--change to auto add JS later-->
<script language="JavaScript" src="/cms/js/jquery.validate.js"></script>
<script language="JavaScript" src="/cms/js/autocomplete/textarea.js"></script>

<link media="all" href="/cms/js/jcrop/css/jquery.Jcrop.css" type="text/css" rel="stylesheet"> 
</head>

<body>
{#include file="$navigation"#}
<div style="float:right;" id="login"></div>
<script>
$(document).ready(function() {	

});	
  function validate_form(form){
	  if (validator.form())  form.submit(); else alert('Some fields has error. Please check and resubmit');
  }
</script>

<H1><span id="parent_key_label"></span>Edit a record of  Event question</H1>
<form name="form_edit" id="form_edit" method="post" action="{#$self_url#}" >	
<div class='tableWrapper' style="width:100%;margin:0;padding:0;">
  <div class='tableHeader' >

	<ul class="tableActions">
	
  <li><input class="psbutton" onmouseover="this.className='psbuttonhover'" onmouseout="this.className='psbutton'" name="Submit" value=" 儲存 " onclick="form.subaction.value='edit_after_update'; form.submit();" type="button"></li>
  <li><input class="psbutton" onmouseover="this.className='psbuttonhover'" onmouseout="this.className='psbutton'" type="submit" name="Submit" value=" 確定 "></li>
  <li><input class="psbutton" onmouseover="this.className='psbuttonhover'" onmouseout="this.className='psbutton'" name="dummy" value=" 取消 " onclick="javascript:window.location.href='{#$self_url#}/list/{#$oid#}'" type="button"></li>  
<li><input class="psbutton" onmouseover="this.className='psbuttonhover'" onmouseout="this.className='psbutton'" name="Submit" value=" 刪除 " onclick="form.action.value='del'; form.submit();" type="button"></li>
	</ul>

  <div class='clear'></div>
  <div class='corner left'></div>
  <div class='corner right'></div>
  </div>	
	
<table border="0" cellspacing='0' >
<tr id="tr_id"><td><B>id</B></td>
<td id="td_id">{#$edit_data.id#}</td></tr>
<tr id="tr_cname"><td><B>問題</B></td>
<td id="td_cname"><input type="text" id="field_cname" name="cname"  size="80" value="{#$edit_data.cname#}"></td></tr>
<tr id="tr_type"><td><B>類型</B></td>
<td id="td_type">{#$edit_data.type#}</td></tr>
<tr id="tr_option_num"><td><B>option_num</B></td>
<td id="td_option_num">{#$edit_data.option_num#}</td></tr>
<tr id="tr_option_1"><td><B>選項 1</B></td>
<td id="td_option_1"><input type="text" id="field_option_1" name="option_1"  size="80" value="{#$edit_data.option_1#}"></td></tr>
<tr id="tr_option_2"><td><B>選項 2</B></td>
<td id="td_option_2"><input type="text" id="field_option_2" name="option_2"  size="80" value="{#$edit_data.option_2#}"></td></tr>
<tr id="tr_option_3"><td><B>選項 3</B></td>
<td id="td_option_3"><input type="text" id="field_option_3" name="option_3"  size="80" value="{#$edit_data.option_3#}"></td></tr>
<tr id="tr_option_4"><td><B>選項 4</B></td>
<td id="td_option_4"><input type="text" id="field_option_4" name="option_4"  size="80" value="{#$edit_data.option_4#}"></td></tr>
<tr id="tr_option_5"><td><B>選項 5</B></td>
<td id="td_option_5"><input type="text" id="field_option_5" name="option_5"  size="80" value="{#$edit_data.option_5#}"></td></tr>
<tr id="tr_option_6"><td><B>選項 6</B></td>
<td id="td_option_6"><input type="text" id="field_option_6" name="option_6"  size="80" value="{#$edit_data.option_6#}"></td></tr>
<tr id="tr_option_7"><td><B>選項 7</B></td>
<td id="td_option_7"><input type="text" id="field_option_7" name="option_7"  size="80" value="{#$edit_data.option_7#}"></td></tr>
<tr id="tr_option_8"><td><B>選項 8</B></td>
<td id="td_option_8"><input type="text" id="field_option_8" name="option_8"  size="80" value="{#$edit_data.option_8#}"></td></tr>
<tr id="tr_priority"><td><B>次序 (數大排先)</B></td>
<td id="td_priority"><input id="field_priority" type="text" name="priority" value="{#$edit_data.priority#}"></td></tr>
<tr id="tr_status"><td><B>上線狀態</B></td>
<td id="td_status">{#$edit_data.status#}</td></tr>
<tr id="tr_addtime"><td><B>建立時間</B></td>
<td id="td_addtime">{#$edit_data.addtime#}</td></tr>
<tr id="tr_lastmodify"><td><B>更新時間</B></td>
<td id="td_lastmodify">{#$edit_data.lastmodify#}</td></tr>
  <tr>
    <td>&nbsp;</td>
    <td><input type="hidden" name="id" value="{#$edit_data.id#}">
     	<input type="hidden" name="oid" value="{#$edit_data.oid#}">
    <input type="hidden" name="action" value="update"><input name="subaction" type="hidden">
	<ul class="tableActions">
    
  <li><input class="psbutton" onmouseover="this.className='psbuttonhover'" onmouseout="this.className='psbutton'" name="Submit" value=" 儲存 " onclick="form.subaction.value='edit_after_update'; form.submit();" type="button"></li>
  <li><input class="psbutton" onmouseover="this.className='psbuttonhover'" onmouseout="this.className='psbutton'" type="submit" name="Submit" value=" 確定 "></li>
  <li><input class="psbutton" onmouseover="this.className='psbuttonhover'" onmouseout="this.className='psbutton'" name="dummy" value=" 取消 " onclick="javascript:window.location.href='{#$self_url#}/list/{#$oid#}'" type="button"></li>  
<li><input class="psbutton" onmouseover="this.className='psbuttonhover'" onmouseout="this.className='psbutton'" name="Submit" value=" 刪除 " onclick="form.action.value='del'; form.submit();" type="button"></li>
	</ul>
  </td>
  </tr>
</table>

</form> 

<script type="text/javascript">
$(function(){
  $(".tips").tipTip({defaultPosition: "right", edgeOffset: 10});
});
</script>

<script type="text/javascript">
//$(function(){
//});

//$(document).ready(function() {	
//});
</script>

<script type="text/javascript">
var selected_type = '';
var option_num  = 1;
$().ready(function(){
   selected_type = $("select[name='type']").val();
   option_num = $("select[name='option_num']").val();
   if(selected_type== 1 || selected_type== 2){
         for (var i=1;i<=8;i++){
            $("#tr_option_"+i).hide();
         }
         $("#tr_option_num").hide();
   }else if(selected_type == 3 || selected_type == 4){
		console.info(option_num);
		for (var i=1;i<=8;i++){
			if(i <=option_num){
				$("#tr_option_"+i).show();
            }else{
				$("#tr_option_"+i).hide();
			}
      }
   }
});

$("select[name='type']").change(function() {
   $(":selected", this).each(function () {
      selected_type = $(this).val();
      if(selected_type == 3 || selected_type == 4){
         $("#tr_option_num").show();
         $("#tr_option_1").show();
      }else{
         for (var i=1;i<=8;i++){
            $("#tr_option_"+i).hide();
         }
         $("#tr_option_num").hide();
      }
   });
});
			
$("select[name='option_num']").change(function() {
   $(":selected", this).each(function () {
      var num = $(this).val();

      if(selected_type == 3 || selected_type == 4){
         for (var i=1;i<=8;i++){
            if(i <=num){
               $("#tr_option_"+i).show();
            }else{
               $("#tr_option_"+i).hide();
            }
         }
      }else{
         for (var i=1;i<=8;i++){
			$("#tr_option_"+i).hide();
		}
	   $("#tr_option_num").hide();
	  }
   });
});

/*
function hidden_rows_by_type(type){

  var myArray = [
    ['n_coming_issue'], // show when type = 1 is selected
    [ 'fix_issue'] ,  // show when type = 2 is selected
  ];

  for (var i=0; i<myArray.length; i++) {
    if (type == i + 1){
       for (var j=0; j<myArray[i].length; j++){
         $('#tr_'+myArray[i][j]).show();
       }
    } else {
       for (var j=0; j<myArray[i].length; j++){
        $('#tr_'+myArray[i][j]).hide();
       }
    }
  }
}

$(document).ready(function() {	

   var fieldname = 'type';

	var type = parseInt($('[name|="'+fieldname+'"]').val());
	hidden_rows_by_type(type);

	$('[name|="'+fieldname+'"]').change(function() {
		hidden_rows_by_type(parseInt($(this).val()));
	});

});
*/

</script>
<!--POSTRUNJS-->
</body>
</html>
